﻿//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------
/*
	based on code from http://www.khronos.org/registry/gles/api/2.0/gl2.h
	and http://www.khronos.org/registry/gles/api/2.0/gl2ext.h
*/

#pragma once

#include "Base/Include/Common.h"

#define GLES_APIENTRY	CALLBACK
#define GLES_API		extern

namespace gles
{

typedef void						GLvoid;
typedef char						GLchar;
typedef unsigned int				GLenum;
typedef unsigned char				GLboolean;
typedef unsigned int				GLbitfield;
typedef UX_STL::UXTypes::int8		GLbyte;
typedef short						GLshort;
typedef int							GLint;
typedef int							GLsizei;
typedef UX_STL::UXTypes::uint8		GLubyte;
typedef unsigned short				GLushort;
typedef unsigned int				GLuint;
typedef float						GLfloat;
typedef float						GLclampf;
typedef UX_STL::UXTypes::fixed32_t	GLfixed;
typedef intptr_t					GLintptr;
typedef ssize_t						GLsizeiptr;

#define CHECK_SIZEOF( _type, _size_in_bits ) \
	STATIC_ASSERTE( (sizeof(_type)<<3) == _size_in_bits )

CHECK_SIZEOF( GLchar, 8 );
CHECK_SIZEOF( GLenum, 32 );
CHECK_SIZEOF( GLboolean, 8 );
CHECK_SIZEOF( GLbitfield, 32 );
CHECK_SIZEOF( GLbyte, 8 );
CHECK_SIZEOF( GLshort, 16 );
CHECK_SIZEOF( GLint, 32 );
CHECK_SIZEOF( GLsizei, 32 );
CHECK_SIZEOF( GLubyte, 8 );
CHECK_SIZEOF( GLushort, 16 );
CHECK_SIZEOF( GLuint, 32 );
CHECK_SIZEOF( GLfloat, 32 );
CHECK_SIZEOF( GLclampf, 32 );
CHECK_SIZEOF( GLfixed, 32 );
CHECK_SIZEOF( GLintptr, PLATFORM_BITS );
CHECK_SIZEOF( GLsizeiptr, PLATFORM_BITS );


enum {

	/* ClearBufferMask */
		GL_DEPTH_BUFFER_BIT              = 0x00000100,
		GL_STENCIL_BUFFER_BIT            = 0x00000400,
		GL_COLOR_BUFFER_BIT              = 0x00004000,

	/* Boolean */
		GL_FALSE                         = 0,
		GL_TRUE                          = 1,

	/* BeginMode */
		GL_POINTS                        = 0x0000,
		GL_LINES                         = 0x0001,
		GL_LINE_LOOP                     = 0x0002,
		GL_LINE_STRIP                    = 0x0003,
		GL_TRIANGLES                     = 0x0004,
		GL_TRIANGLE_STRIP                = 0x0005,
		GL_TRIANGLE_FAN                  = 0x0006,

	/* AlphaFunction (not supported in ES20) */
	/*	GL_NEVER */
	/*	GL_LESS */
	/*	GL_EQUAL */
	/*	GL_LEQUAL */
	/*	GL_GREATER */
	/*	GL_NOTEQUAL */
	/*	GL_GEQUAL */
	/*	GL_ALWAYS */

	/* BlendingFactorDest */
		GL_ZERO                          = 0,
		GL_ONE                           = 1,
		GL_SRC_COLOR                     = 0x0300,
		GL_ONE_MINUS_SRC_COLOR           = 0x0301,
		GL_SRC_ALPHA                     = 0x0302,
		GL_ONE_MINUS_SRC_ALPHA           = 0x0303,
		GL_DST_ALPHA                     = 0x0304,
		GL_ONE_MINUS_DST_ALPHA           = 0x0305,

	/* BlendingFactorSrc */
	/*		GL_ZERO */
	/*		GL_ONE */
		GL_DST_COLOR                     = 0x0306,
		GL_ONE_MINUS_DST_COLOR           = 0x0307,
		GL_SRC_ALPHA_SATURATE            = 0x0308,
	/*	GL_SRC_ALPHA */
	/*	GL_ONE_MINUS_SRC_ALPHA */
	/*	GL_DST_ALPHA */
	/*	GL_ONE_MINUS_DST_ALPHA */

	/* BlendEquationSeparate */
		GL_FUNC_ADD                      = 0x8006,
		GL_BLEND_EQUATION                = 0x8009,
		GL_BLEND_EQUATION_RGB            = 0x8009,    /* same as BLEND_EQUATION */
		GL_BLEND_EQUATION_ALPHA          = 0x883D,

	/* BlendSubtract */
		GL_FUNC_SUBTRACT                 = 0x800A,
		GL_FUNC_REVERSE_SUBTRACT         = 0x800B,

	/* Separate Blend Functions */
		GL_BLEND_DST_RGB                 = 0x80C8,
		GL_BLEND_SRC_RGB                 = 0x80C9,
		GL_BLEND_DST_ALPHA               = 0x80CA,
		GL_BLEND_SRC_ALPHA               = 0x80CB,
		GL_CONSTANT_COLOR                = 0x8001,
		GL_ONE_MINUS_CONSTANT_COLOR      = 0x8002,
		GL_CONSTANT_ALPHA                = 0x8003,
		GL_ONE_MINUS_CONSTANT_ALPHA      = 0x8004,
		GL_BLEND_COLOR                   = 0x8005,

	/* Buffer Objects */
		GL_ARRAY_BUFFER                  = 0x8892,
		GL_ELEMENT_ARRAY_BUFFER          = 0x8893,
		GL_ARRAY_BUFFER_BINDING          = 0x8894,
		GL_ELEMENT_ARRAY_BUFFER_BINDING  = 0x8895,

		GL_STREAM_DRAW                   = 0x88E0,
		GL_STATIC_DRAW                   = 0x88E4,
		GL_DYNAMIC_DRAW                  = 0x88E8,

		GL_BUFFER_SIZE                   = 0x8764,
		GL_BUFFER_USAGE                  = 0x8765,

		GL_CURRENT_VERTEX_ATTRIB         = 0x8626,

	/* CullFaceMode */
		GL_FRONT                         = 0x0404,
		GL_BACK                          = 0x0405,
		GL_FRONT_AND_BACK                = 0x0408,

	/* DepthFunction */
	/*	GL_NEVER */
	/*	GL_LESS */
	/*	GL_EQUAL */
	/*	GL_LEQUAL */
	/*	GL_GREATER */
	/*	GL_NOTEQUAL */
	/*	GL_GEQUAL */
	/*	GL_ALWAYS */

	/* EnableCap */
		GL_TEXTURE_2D                    = 0x0DE1,
		GL_CULL_FACE                     = 0x0B44,
		GL_BLEND                         = 0x0BE2,
		GL_DITHER                        = 0x0BD0,
		GL_STENCIL_TEST                  = 0x0B90,
		GL_DEPTH_TEST                    = 0x0B71,
		GL_SCISSOR_TEST                  = 0x0C11,
		GL_POLYGON_OFFSET_FILL           = 0x8037,
		GL_SAMPLE_ALPHA_TO_COVERAGE      = 0x809E,
		GL_SAMPLE_COVERAGE               = 0x80A0,

	/* ErrorCode */
		GL_NO_ERROR                      = 0,
		GL_INVALID_ENUM                  = 0x0500,
		GL_INVALID_VALUE                 = 0x0501,
		GL_INVALID_OPERATION             = 0x0502,
		GL_OUT_OF_MEMORY                 = 0x0505,

	/* FrontFaceDirection */
		GL_CW                            = 0x0900,
		GL_CCW                           = 0x0901,

	/* GetPName */
		GL_LINE_WIDTH                    = 0x0B21,
		GL_ALIASED_POINT_SIZE_RANGE      = 0x846D,
		GL_ALIASED_LINE_WIDTH_RANGE      = 0x846E,
		GL_CULL_FACE_MODE                = 0x0B45,
		GL_FRONT_FACE                    = 0x0B46,
		GL_DEPTH_RANGE                   = 0x0B70,
		GL_DEPTH_WRITEMASK               = 0x0B72,
		GL_DEPTH_CLEAR_VALUE             = 0x0B73,
		GL_DEPTH_FUNC                    = 0x0B74,
		GL_STENCIL_CLEAR_VALUE           = 0x0B91,
		GL_STENCIL_FUNC                  = 0x0B92,
		GL_STENCIL_FAIL                  = 0x0B94,
		GL_STENCIL_PASS_DEPTH_FAIL       = 0x0B95,
		GL_STENCIL_PASS_DEPTH_PASS       = 0x0B96,
		GL_STENCIL_REF                   = 0x0B97,
		GL_STENCIL_VALUE_MASK            = 0x0B93,
		GL_STENCIL_WRITEMASK             = 0x0B98,
		GL_STENCIL_BACK_FUNC             = 0x8800,
		GL_STENCIL_BACK_FAIL             = 0x8801,
		GL_STENCIL_BACK_PASS_DEPTH_FAIL  = 0x8802,
		GL_STENCIL_BACK_PASS_DEPTH_PASS  = 0x8803,
		GL_STENCIL_BACK_REF              = 0x8CA3,
		GL_STENCIL_BACK_VALUE_MASK       = 0x8CA4,
		GL_STENCIL_BACK_WRITEMASK        = 0x8CA5,
		GL_VIEWPORT                      = 0x0BA2,
		GL_SCISSOR_BOX                   = 0x0C10,
	/*	GL_SCISSOR_TEST */
		GL_COLOR_CLEAR_VALUE             = 0x0C22,
		GL_COLOR_WRITEMASK               = 0x0C23,
		GL_UNPACK_ALIGNMENT              = 0x0CF5,
		GL_PACK_ALIGNMENT                = 0x0D05,
		GL_MAX_TEXTURE_SIZE              = 0x0D33,
		GL_MAX_VIEWPORT_DIMS             = 0x0D3A,
		GL_SUBPIXEL_BITS                 = 0x0D50,
		GL_RED_BITS                      = 0x0D52,
		GL_GREEN_BITS                    = 0x0D53,
		GL_BLUE_BITS                     = 0x0D54,
		GL_ALPHA_BITS                    = 0x0D55,
		GL_DEPTH_BITS                    = 0x0D56,
		GL_STENCIL_BITS                  = 0x0D57,
		GL_POLYGON_OFFSET_UNITS          = 0x2A00,
	/*	GL_POLYGON_OFFSET_FILL */
		GL_POLYGON_OFFSET_FACTOR         = 0x8038,
		GL_TEXTURE_BINDING_2D            = 0x8069,
		GL_SAMPLE_BUFFERS                = 0x80A8,
		GL_SAMPLES                       = 0x80A9,
		GL_SAMPLE_COVERAGE_VALUE         = 0x80AA,
		GL_SAMPLE_COVERAGE_INVERT        = 0x80AB,

	/* GetTextureParameter */
	/*	GL_TEXTURE_MAG_FILTER */
	/*	GL_TEXTURE_MIN_FILTER */
	/*	GL_TEXTURE_WRAP_S */
	/*	GL_TEXTURE_WRAP_T */

		GL_NUM_COMPRESSED_TEXTURE_FORMATS= 0x86A2,
		GL_COMPRESSED_TEXTURE_FORMATS    = 0x86A3,

	/* HintMode */
		GL_DONT_CARE                     = 0x1100,
		GL_FASTEST                       = 0x1101,
		GL_NICEST                        = 0x1102,

	/* HintTarget */
		GL_GENERATE_MIPMAP_HINT           = 0x8192,

	/* DataType */
		GL_BYTE                          = 0x1400,
		GL_UNSIGNED_BYTE                 = 0x1401,
		GL_SHORT                         = 0x1402,
		GL_UNSIGNED_SHORT                = 0x1403,
		GL_INT                           = 0x1404,
		GL_UNSIGNED_INT                  = 0x1405,
		GL_FLOAT                         = 0x1406,
		GL_FIXED                         = 0x140C,

	/* PixelFormat */
		GL_DEPTH_COMPONENT               = 0x1902,
		GL_ALPHA                         = 0x1906,
		GL_RGB                           = 0x1907,
		GL_RGBA                          = 0x1908,
		GL_LUMINANCE                     = 0x1909,
		GL_LUMINANCE_ALPHA               = 0x190A,

	/* PixelType */
	/*	GL_UNSIGNED_BYTE */
		GL_UNSIGNED_SHORT_4_4_4_4        = 0x8033,
		GL_UNSIGNED_SHORT_5_5_5_1        = 0x8034,
		GL_UNSIGNED_SHORT_5_6_5          = 0x8363,

	/* Shaders */
		GL_FRAGMENT_SHADER                 = 0x8B30,
		GL_VERTEX_SHADER                   = 0x8B31,
		GL_MAX_VERTEX_ATTRIBS              = 0x8869,
		GL_MAX_VERTEX_UNIFORM_VECTORS      = 0x8DFB,
		GL_MAX_VARYING_VECTORS             = 0x8DFC,
		GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS= 0x8B4D,
		GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS  = 0x8B4C,
		GL_MAX_TEXTURE_IMAGE_UNITS         = 0x8872,
		GL_MAX_FRAGMENT_UNIFORM_VECTORS    = 0x8DFD,
		GL_SHADER_TYPE                     = 0x8B4F,
		GL_DELETE_STATUS                   = 0x8B80,
		GL_LINK_STATUS                     = 0x8B82,
		GL_VALIDATE_STATUS                 = 0x8B83,
		GL_ATTACHED_SHADERS                = 0x8B85,
		GL_ACTIVE_UNIFORMS                 = 0x8B86,
		GL_ACTIVE_UNIFORM_MAX_LENGTH       = 0x8B87,
		GL_ACTIVE_ATTRIBUTES               = 0x8B89,
		GL_ACTIVE_ATTRIBUTE_MAX_LENGTH     = 0x8B8A,
		GL_SHADING_LANGUAGE_VERSION        = 0x8B8C,
		GL_CURRENT_PROGRAM                 = 0x8B8D,

	/* StencilFunction */
		GL_NEVER                         = 0x0200,
		GL_LESS                          = 0x0201,
		GL_EQUAL                         = 0x0202,
		GL_LEQUAL                        = 0x0203,
		GL_GREATER                       = 0x0204,
		GL_NOTEQUAL                      = 0x0205,
		GL_GEQUAL                        = 0x0206,
		GL_ALWAYS                        = 0x0207,

	/* StencilOp */
	/*	GL_ZERO */
		GL_KEEP                          = 0x1E00,
		GL_REPLACE                       = 0x1E01,
		GL_INCR                          = 0x1E02,
		GL_DECR                          = 0x1E03,
		GL_INVERT                        = 0x150A,
		GL_INCR_WRAP                     = 0x8507,
		GL_DECR_WRAP                     = 0x8508,

	/* StringName */
		GL_VENDOR                        = 0x1F00,
		GL_RENDERER                      = 0x1F01,
		GL_VERSION                       = 0x1F02,
		GL_EXTENSIONS                    = 0x1F03,

	/* TextureMagFilter */
		GL_NEAREST                       = 0x2600,
		GL_LINEAR                        = 0x2601,

	/* TextureMinFilter */
	/*	GL_NEAREST */
	/*	GL_LINEAR */
		GL_NEAREST_MIPMAP_NEAREST        = 0x2700,
		GL_LINEAR_MIPMAP_NEAREST         = 0x2701,
		GL_NEAREST_MIPMAP_LINEAR         = 0x2702,
		GL_LINEAR_MIPMAP_LINEAR          = 0x2703,

	/* TextureParameterName */
		GL_TEXTURE_MAG_FILTER            = 0x2800,
		GL_TEXTURE_MIN_FILTER            = 0x2801,
		GL_TEXTURE_WRAP_S                = 0x2802,
		GL_TEXTURE_WRAP_T                = 0x2803,

	/* TextureTarget */
	/*	GL_TEXTURE_2D */
		GL_TEXTURE                       = 0x1702,

		GL_TEXTURE_CUBE_MAP              = 0x8513,
		GL_TEXTURE_BINDING_CUBE_MAP      = 0x8514,
		GL_TEXTURE_CUBE_MAP_POSITIVE_X   = 0x8515,
		GL_TEXTURE_CUBE_MAP_NEGATIVE_X   = 0x8516,
		GL_TEXTURE_CUBE_MAP_POSITIVE_Y   = 0x8517,
		GL_TEXTURE_CUBE_MAP_NEGATIVE_Y   = 0x8518,
		GL_TEXTURE_CUBE_MAP_POSITIVE_Z   = 0x8519,
		GL_TEXTURE_CUBE_MAP_NEGATIVE_Z   = 0x851A,
		GL_MAX_CUBE_MAP_TEXTURE_SIZE     = 0x851C,

	/* TextureUnit */
		GL_TEXTURE0                      = 0x84C0,
		GL_TEXTURE1                      = 0x84C1,
		GL_TEXTURE2                      = 0x84C2,
		GL_TEXTURE3                      = 0x84C3,
		GL_TEXTURE4                      = 0x84C4,
		GL_TEXTURE5                      = 0x84C5,
		GL_TEXTURE6                      = 0x84C6,
		GL_TEXTURE7                      = 0x84C7,
		GL_TEXTURE8                      = 0x84C8,
		GL_TEXTURE9                      = 0x84C9,
		GL_TEXTURE10                     = 0x84CA,
		GL_TEXTURE11                     = 0x84CB,
		GL_TEXTURE12                     = 0x84CC,
		GL_TEXTURE13                     = 0x84CD,
		GL_TEXTURE14                     = 0x84CE,
		GL_TEXTURE15                     = 0x84CF,
		GL_TEXTURE16                     = 0x84D0,
		GL_TEXTURE17                     = 0x84D1,
		GL_TEXTURE18                     = 0x84D2,
		GL_TEXTURE19                     = 0x84D3,
		GL_TEXTURE20                     = 0x84D4,
		GL_TEXTURE21                     = 0x84D5,
		GL_TEXTURE22                     = 0x84D6,
		GL_TEXTURE23                     = 0x84D7,
		GL_TEXTURE24                     = 0x84D8,
		GL_TEXTURE25                     = 0x84D9,
		GL_TEXTURE26                     = 0x84DA,
		GL_TEXTURE27                     = 0x84DB,
		GL_TEXTURE28                     = 0x84DC,
		GL_TEXTURE29                     = 0x84DD,
		GL_TEXTURE30                     = 0x84DE,
		GL_TEXTURE31                     = 0x84DF,
		GL_ACTIVE_TEXTURE                = 0x84E0,

	/* TextureWrapMode */
		GL_REPEAT                        = 0x2901,
		GL_CLAMP_TO_EDGE                 = 0x812F,
		GL_MIRRORED_REPEAT               = 0x8370,

	/* Uniform Types */
		GL_FLOAT_VEC2                    = 0x8B50,
		GL_FLOAT_VEC3                    = 0x8B51,
		GL_FLOAT_VEC4                    = 0x8B52,
		GL_INT_VEC2                      = 0x8B53,
		GL_INT_VEC3                      = 0x8B54,
		GL_INT_VEC4                      = 0x8B55,
		GL_BOOL                          = 0x8B56,
		GL_BOOL_VEC2                     = 0x8B57,
		GL_BOOL_VEC3                     = 0x8B58,
		GL_BOOL_VEC4                     = 0x8B59,
		GL_FLOAT_MAT2                    = 0x8B5A,
		GL_FLOAT_MAT3                    = 0x8B5B,
		GL_FLOAT_MAT4                    = 0x8B5C,
		GL_SAMPLER_2D                    = 0x8B5E,
		GL_SAMPLER_CUBE                  = 0x8B60,

	/* Vertex Arrays */
		GL_VERTEX_ATTRIB_ARRAY_ENABLED       = 0x8622,
		GL_VERTEX_ATTRIB_ARRAY_SIZE          = 0x8623,
		GL_VERTEX_ATTRIB_ARRAY_STRIDE        = 0x8624,
		GL_VERTEX_ATTRIB_ARRAY_TYPE          = 0x8625,
		GL_VERTEX_ATTRIB_ARRAY_NORMALIZED    = 0x886A,
		GL_VERTEX_ATTRIB_ARRAY_POINTER       = 0x8645,
		GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING= 0x889F,

	/* Read Format */
		GL_IMPLEMENTATION_COLOR_READ_TYPE  = 0x8B9A,
		GL_IMPLEMENTATION_COLOR_READ_FORMAT= 0x8B9B,

	/* Shader Source */
		GL_COMPILE_STATUS                = 0x8B81,
		GL_INFO_LOG_LENGTH               = 0x8B84,
		GL_SHADER_SOURCE_LENGTH          = 0x8B88,
		GL_SHADER_COMPILER               = 0x8DFA,

	/* Shader Binary */
		GL_SHADER_BINARY_FORMATS         = 0x8DF8,
		GL_NUM_SHADER_BINARY_FORMATS     = 0x8DF9,

	/* Shader Precision-Specified Types */
		GL_LOW_FLOAT                     = 0x8DF0,
		GL_MEDIUM_FLOAT                  = 0x8DF1,
		GL_HIGH_FLOAT                    = 0x8DF2,
		GL_LOW_INT                       = 0x8DF3,
		GL_MEDIUM_INT                    = 0x8DF4,
		GL_HIGH_INT                      = 0x8DF5,

	/* Framebuffer Object. */
		GL_FRAMEBUFFER                   = 0x8D40,
		GL_RENDERBUFFER                  = 0x8D41,

		GL_RGBA4                         = 0x8056,
		GL_RGB5_A1                       = 0x8057,
		GL_RGB565                        = 0x8D62,
		GL_DEPTH_COMPONENT16             = 0x81A5,
		GL_STENCIL_INDEX8                = 0x8D48,

		GL_RENDERBUFFER_WIDTH            = 0x8D42,
		GL_RENDERBUFFER_HEIGHT           = 0x8D43,
		GL_RENDERBUFFER_INTERNAL_FORMAT  = 0x8D44,
		GL_RENDERBUFFER_RED_SIZE         = 0x8D50,
		GL_RENDERBUFFER_GREEN_SIZE       = 0x8D51,
		GL_RENDERBUFFER_BLUE_SIZE        = 0x8D52,
		GL_RENDERBUFFER_ALPHA_SIZE       = 0x8D53,
		GL_RENDERBUFFER_DEPTH_SIZE       = 0x8D54,
		GL_RENDERBUFFER_STENCIL_SIZE     = 0x8D55,

		GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE          = 0x8CD0,
		GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME          = 0x8CD1,
		GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL        = 0x8CD2,
		GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE= 0x8CD3,

		GL_COLOR_ATTACHMENT0             = 0x8CE0,
		GL_DEPTH_ATTACHMENT              = 0x8D00,
		GL_STENCIL_ATTACHMENT            = 0x8D20,

		GL_NONE                          = 0,

		GL_FRAMEBUFFER_COMPLETE                     = 0x8CD5,
		GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT        = 0x8CD6,
		GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT= 0x8CD7,
		GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS        = 0x8CD9,
		GL_FRAMEBUFFER_UNSUPPORTED                  = 0x8CDD,

		GL_FRAMEBUFFER_BINDING           = 0x8CA6,
		GL_RENDERBUFFER_BINDING          = 0x8CA7,
		GL_MAX_RENDERBUFFER_SIZE         = 0x84E8,

		GL_INVALID_FRAMEBUFFER_OPERATION = 0x0506,

};	// enum
}	// gles


// OpenGL 2.0 Core functions
#define GLES_CORE_FUNCTIONS( _buildFunc ) \
	/* A */ \
	_buildFunc( void, ActiveTexture, (GLenum texture), void() ) \
	_buildFunc( void, AttachShader, (GLuint program, GLuint shader), void() ) \
	/* B */ \
	_buildFunc( void, BindAttribLocation, (GLuint program, GLuint index, const GLchar* name), void() ) \
	_buildFunc( void, BindBuffer, (GLenum target, GLuint buffer), void() ) \
	_buildFunc( void, BindFramebuffer, (GLenum target, GLuint framebuffer), void() ) \
	_buildFunc( void, BindRenderbuffer, (GLenum target, GLuint renderbuffer), void() ) \
	_buildFunc( void, BindTexture, (GLenum target, GLuint texture), void() ) \
	_buildFunc( void, BlendColor, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), void() ) \
	_buildFunc( void, BlendEquation, ( GLenum mode ), void() ) \
	_buildFunc( void, BlendEquationSeparate, (GLenum modeRGB, GLenum modeAlpha), void() ) \
	_buildFunc( void, BlendFunc, (GLenum sfactor, GLenum dfactor), void() ) \
	_buildFunc( void, BlendFuncSeparate, (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha), void() ) \
	_buildFunc( void, BufferData, (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage), void() ) \
	_buildFunc( void, BufferSubData, (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data), void() ) \
	/* C */ \
	_buildFunc( GLenum, CheckFramebufferStatus, (GLenum target), 0 ) \
	_buildFunc( void, Clear, (GLbitfield mask), void() ) \
	_buildFunc( void, ClearColor, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), void() ) \
	_buildFunc( void, ClearDepthf, (GLclampf depth), void() ) \
	_buildFunc( void, ClearStencil, (GLint s), void() ) \
	_buildFunc( void, ColorMask, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha), void() ) \
	_buildFunc( void, CompileShader, (GLuint shader), void() ) \
	_buildFunc( void, CompressedTexImage2D, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data), void() ) \
	_buildFunc( void, CompressedTexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data), void() ) \
	_buildFunc( void, CopyTexImage2D, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border), void() ) \
	_buildFunc( void, CopyTexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height), void() ) \
	_buildFunc( GLuint, CreateProgram, (void), 0 ) \
	_buildFunc( GLuint, CreateShader, (GLenum type), 0 ) \
	_buildFunc( void, CullFace, (GLenum mode), void() ) \
	/* D */ \
	_buildFunc( void, DeleteBuffers, (GLsizei n, const GLuint* buffers), void() ) \
	_buildFunc( void, DeleteFramebuffers, (GLsizei n, const GLuint* framebuffers), void() ) \
	_buildFunc( void, DeleteProgram, (GLuint program), void() ) \
	_buildFunc( void, DeleteRenderbuffers, (GLsizei n, const GLuint* renderbuffers), void() ) \
	_buildFunc( void, DeleteShader, (GLuint shader), void() ) \
	_buildFunc( void, DeleteTextures, (GLsizei n, const GLuint* textures), void() ) \
	_buildFunc( void, DepthFunc, (GLenum func), void() ) \
	_buildFunc( void, DepthMask, (GLboolean flag), void() ) \
	_buildFunc( void, DepthRangef, (GLclampf zNear, GLclampf zFar), void() ) \
	_buildFunc( void, DetachShader, (GLuint program, GLuint shader), void() ) \
	_buildFunc( void, Disable, (GLenum cap), void() ) \
	_buildFunc( void, DisableVertexAttribArray, (GLuint index), void() ) \
	_buildFunc( void, DrawArrays, (GLenum mode, GLint first, GLsizei count), void() ) \
	_buildFunc( void, DrawElements, (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices), void() ) \
	/* E */ \
	_buildFunc( void, Enable, (GLenum cap), void() ) \
	_buildFunc( void, EnableVertexAttribArray, (GLuint index), void() ) \
	/* F */ \
	_buildFunc( void, Finish, (void), void() ) \
	_buildFunc( void, Flush, (void), void() ) \
	_buildFunc( void, FramebufferRenderbuffer, (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer), void() ) \
	_buildFunc( void, FramebufferTexture2D, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level), void() ) \
	_buildFunc( void, FrontFace, (GLenum mode), void() ) \
	/* G */ \
	_buildFunc( void, GenBuffers, (GLsizei n, GLuint* buffers), void() ) \
	_buildFunc( void, GenerateMipmap, (GLenum target), void() ) \
	_buildFunc( void, GenFramebuffers, (GLsizei n, GLuint* framebuffers), void() ) \
	_buildFunc( void, GenRenderbuffers, (GLsizei n, GLuint* renderbuffers), void() ) \
	_buildFunc( void, GenTextures, (GLsizei n, GLuint* textures), void() ) \
	_buildFunc( void, GetActiveAttrib, (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name), void() ) \
	_buildFunc( void, GetActiveUniform, (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name), void() ) \
	_buildFunc( void, GetAttachedShaders, (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders), void() ) \
	_buildFunc( GLint,  GetAttribLocation, (GLuint program, const GLchar* name), 0 ) \
	_buildFunc( void, GetBooleanv, (GLenum pname, GLboolean* params), void() ) \
	_buildFunc( void, GetBufferParameteriv, (GLenum target, GLenum pname, GLint* params), void() ) \
	_buildFunc( GLenum, GetError, (void), 0 ) \
	_buildFunc( void, GetFloatv, (GLenum pname, GLfloat* params), void() ) \
	_buildFunc( void, GetFramebufferAttachmentParameteriv, (GLenum target, GLenum attachment, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetIntegerv, (GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetProgramiv, (GLuint program, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetProgramInfoLog, (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog), void() ) \
	_buildFunc( void, GetRenderbufferParameteriv, (GLenum target, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetShaderiv, (GLuint shader, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetShaderInfoLog, (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog), void() ) \
	_buildFunc( void, GetShaderPrecisionFormat, (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision), void() ) \
	_buildFunc( void, GetShaderSource, (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source), void() ) \
	_buildFunc( const GLubyte*, GetString, (GLenum name), ((const GLubyte *)0) ) \
	_buildFunc( void, GetTexParameterfv, (GLenum target, GLenum pname, GLfloat* params), void() ) \
	_buildFunc( void, GetTexParameteriv, (GLenum target, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetUniformfv, (GLuint program, GLint location, GLfloat* params), void() ) \
	_buildFunc( void, GetUniformiv, (GLuint program, GLint location, GLint* params), void() ) \
	_buildFunc( GLint,  GetUniformLocation, (GLuint program, const GLchar* name), 0 ) \
	_buildFunc( void, GetVertexAttribfv, (GLuint index, GLenum pname, GLfloat* params), void() ) \
	_buildFunc( void, GetVertexAttribiv, (GLuint index, GLenum pname, GLint* params), void() ) \
	_buildFunc( void, GetVertexAttribPointerv, (GLuint index, GLenum pname, GLvoid** pointer), void() ) \
	/* H */ \
	_buildFunc( void, Hint, (GLenum target, GLenum mode), void() ) \
	/* I */ \
	_buildFunc( GLboolean, IsBuffer, (GLuint buffer), GL_FALSE ) \
	_buildFunc( GLboolean, IsEnabled, (GLenum cap), GL_FALSE ) \
	_buildFunc( GLboolean, IsFramebuffer, (GLuint framebuffer), GL_FALSE ) \
	_buildFunc( GLboolean, IsProgram, (GLuint program), GL_FALSE ) \
	_buildFunc( GLboolean, IsRenderbuffer, (GLuint renderbuffer), GL_FALSE ) \
	_buildFunc( GLboolean, IsShader, (GLuint shader), GL_FALSE ) \
	_buildFunc( GLboolean, IsTexture, (GLuint texture), GL_FALSE ) \
	/* L */ \
	_buildFunc( void, LineWidth, (GLfloat width), void() ) \
	_buildFunc( void, LinkProgram, (GLuint program), void() ) \
	/* P */ \
	_buildFunc( void, PixelStorei, (GLenum pname, GLint param), void() ) \
	_buildFunc( void, PolygonOffset, (GLfloat factor, GLfloat units), void() ) \
	/* R */ \
	_buildFunc( void, ReadPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels), void() ) \
	_buildFunc( void, ReleaseShaderCompiler, (void), void() ) \
	_buildFunc( void, RenderbufferStorage, (GLenum target, GLenum internalformat, GLsizei width, GLsizei height), void() ) \
	/* S */ \
	_buildFunc( void, SampleCoverage, (GLclampf value, GLboolean invert), void() ) \
	_buildFunc( void, Scissor, (GLint x, GLint y, GLsizei width, GLsizei height), void() ) \
	_buildFunc( void, ShaderBinary, (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length), void() ) \
	_buildFunc( void, ShaderSource, (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length), void() ) \
	_buildFunc( void, StencilFunc, (GLenum func, GLint ref, GLuint mask), void() ) \
	_buildFunc( void, StencilFuncSeparate, (GLenum face, GLenum func, GLint ref, GLuint mask), void() ) \
	_buildFunc( void, StencilMask, (GLuint mask), void() ) \
	_buildFunc( void, StencilMaskSeparate, (GLenum face, GLuint mask), void() ) \
	_buildFunc( void, StencilOp, (GLenum fail, GLenum zfail, GLenum zpass), void() ) \
	_buildFunc( void, StencilOpSeparate, (GLenum face, GLenum fail, GLenum zfail, GLenum zpass), void() ) \
	/* T */ \
	_buildFunc( void, TexImage2D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels), void() ) \
	_buildFunc( void, TexParameterf, (GLenum target, GLenum pname, GLfloat param), void() ) \
	_buildFunc( void, TexParameterfv, (GLenum target, GLenum pname, const GLfloat* params), void() ) \
	_buildFunc( void, TexParameteri, (GLenum target, GLenum pname, GLint param), void() ) \
	_buildFunc( void, TexParameteriv, (GLenum target, GLenum pname, const GLint* params), void() ) \
	_buildFunc( void, TexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels), void() ) \
	/* U */ \
	_buildFunc( void, Uniform1f, (GLint location, GLfloat x), void() ) \
	_buildFunc( void, Uniform1fv, (GLint location, GLsizei count, const GLfloat* v), void() ) \
	_buildFunc( void, Uniform1i, (GLint location, GLint x), void() ) \
	_buildFunc( void, Uniform1iv, (GLint location, GLsizei count, const GLint* v), void() ) \
	_buildFunc( void, Uniform2f, (GLint location, GLfloat x, GLfloat y), void() ) \
	_buildFunc( void, Uniform2fv, (GLint location, GLsizei count, const GLfloat* v), void() ) \
	_buildFunc( void, Uniform2i, (GLint location, GLint x, GLint y), void() ) \
	_buildFunc( void, Uniform2iv, (GLint location, GLsizei count, const GLint* v), void() ) \
	_buildFunc( void, Uniform3f, (GLint location, GLfloat x, GLfloat y, GLfloat z), void() ) \
	_buildFunc( void, Uniform3fv, (GLint location, GLsizei count, const GLfloat* v), void() ) \
	_buildFunc( void, Uniform3i, (GLint location, GLint x, GLint y, GLint z), void() ) \
	_buildFunc( void, Uniform3iv, (GLint location, GLsizei count, const GLint* v), void() ) \
	_buildFunc( void, Uniform4f, (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w), void() ) \
	_buildFunc( void, Uniform4fv, (GLint location, GLsizei count, const GLfloat* v), void() ) \
	_buildFunc( void, Uniform4i, (GLint location, GLint x, GLint y, GLint z, GLint w), void() ) \
	_buildFunc( void, Uniform4iv, (GLint location, GLsizei count, const GLint* v), void() ) \
	_buildFunc( void, UniformMatrix2fv, (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value), void() ) \
	_buildFunc( void, UniformMatrix3fv, (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value), void() ) \
	_buildFunc( void, UniformMatrix4fv, (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value), void() ) \
	_buildFunc( void, UseProgram, (GLuint program), void() ) \
	/* V */ \
	_buildFunc( void, ValidateProgram, (GLuint program), void() ) \
	_buildFunc( void, VertexAttrib1f, (GLuint indx, GLfloat x), void() ) \
	_buildFunc( void, VertexAttrib1fv, (GLuint indx, const GLfloat* values), void() ) \
	_buildFunc( void, VertexAttrib2f, (GLuint indx, GLfloat x, GLfloat y), void() ) \
	_buildFunc( void, VertexAttrib2fv, (GLuint indx, const GLfloat* values), void() ) \
	_buildFunc( void, VertexAttrib3f, (GLuint indx, GLfloat x, GLfloat y, GLfloat z), void() ) \
	_buildFunc( void, VertexAttrib3fv, (GLuint indx, const GLfloat* values), void() ) \
	_buildFunc( void, VertexAttrib4f, (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w), void() ) \
	_buildFunc( void, VertexAttrib4fv, (GLuint indx, const GLfloat* values), void() ) \
	_buildFunc( void, VertexAttribPointer, (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr), void() ) \
	_buildFunc( void, Viewport, (GLint x, GLint y, GLsizei width, GLsizei height), void() ) \
	

	
#define GLES_CONSTANTS_I( _buildConst ) \
	_buildConst( GLint,			MAX_FRAGMENT_UNIFORM_VECTORS ) \
	_buildConst( GLint,			MAX_VERTEX_UNIFORM_VECTORS ) \
	_buildConst( GLint,			MAX_VERTEX_ATTRIBS ) \
	_buildConst( GLint,			MAX_TEXTURE_IMAGE_UNITS ) \
	_buildConst( GLint,			MAX_TEXTURE_SIZE ) \
	_buildConst( GLint,			MAX_CUBE_MAP_TEXTURE_SIZE ) \
	_buildConst( GLint,			MAX_RENDERBUFFER_SIZE ) \
	_buildConst( _GLivec2_t,	MAX_VIEWPORT_DIMS ) \
	

namespace gles
{
	
	template <typename T, int I>
	struct __GLvec
	{
		typedef __GLvec<T,I>	Self;

		T	_value[I];
		///
		Self &		operator = (const T& val)		{ for (int i = 0; i < I; ++i) _value[i] = val;  return *this; }
		T &			operator [] (int i)				{ return _value[i]; }
		T const &	operator [] (int i)	const		{ return _value[i]; }
		T *			operator & ()					{ return _value; }
		T const *	operator & ()	const			{ return _value; }
	};

	typedef __GLvec< GLint, 2 >		_GLivec2_t;
	

// typedefs //
#define GLES_BUILDTYPEDEF( _retType, _funcName, _funcParams, _retValue ) \
	typedef _retType (GLES_APIENTRY * PFNGL##_funcName##PROC)  _funcParams;

// pointers to functions //
#define GLES_BUILDFUNC( _retType, _funcName, _funcParams, _retValue ) \
	extern PFNGL##_funcName##PROC	gl##_funcName;

// constants //
#define GLES_BUILDCONST( _type, _name ) \
	extern _type	C_GL_##_name;


	GLES_CORE_FUNCTIONS( GLES_BUILDTYPEDEF )
	GLES_CORE_FUNCTIONS( GLES_BUILDFUNC )

	GLES_CONSTANTS_I( GLES_BUILDCONST )

	GLES_API bool GLES_Init ();
	GLES_API void GLES_Delete ();

	GLES_API int  GLES_GetVersion ();	// example version 2.0 returns 200

	GLES_API void GLES_ClearErrors (int maxErrors = 10);
	GLES_API bool GLES_CheckErrors (const UX_STL::UXTypes::uni_c_string &msg = UX_STL::UXTypes::uni_c_string(), int maxErrors = 10);
	GLES_API bool GLES_CheckErrors2 (const char *glcall, const char *func, const char *file, int line);

}	// gles


#define GL_CALL( __func )				{ __func;  ::gles::GLES_CheckErrors2( #__func, UX_FUNCTION_NAME, __FILE__, __LINE__ ); }
#define GL_CALL_R( __func, _ret )		{ __func;  if ( not ::gles::GLES_CheckErrors2( #__func, UX_FUNCTION_NAME, __FILE__, __LINE__ ) ) return _ret; }


//-------------------------------------------------------------------





// EXTENSIONS //


#define GLES_GET_PROGRAM_BINARY( _buildFunc ) \
	_buildFunc( void, GetProgramBinary, (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary), void() ) \
	_buildFunc( void, ProgramBinary, (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length), void() ) \


#define GLES_TEXTURE_3D( _buildFunc ) \
	_buildFunc( void, TexImage3D, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels), void() ) \
	_buildFunc( void, TexSubImage3D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels), void() ) \
	_buildFunc( void, CopyTexSubImage3D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height), void() ) \
	_buildFunc( void, CompressedTexImage3D, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data), void() ) \
	_buildFunc( void, CompressedTexSubImage3D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data), void() ) \
	_buildFunc( void, FramebufferTexture3D, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset), void() ) \


#define GLES_VERTEX_ARRAY_OBJECT( _buildFunc ) \
	_buildFunc( void, BindVertexArray, (GLuint array), void() ) \
	_buildFunc( void, DeleteVertexArrays, (GLsizei n, const GLuint *arrays), void() ) \
	_buildFunc( void, GenVertexArrays, (GLsizei n, GLuint *arrays), void() ) \
	_buildFunc( GLboolean, IsVertexArray, (GLuint array), GL_FALSE ) \


#define GLES_DEBUG_LABEL( _buildFunc ) \
	_buildFunc( void, LabelObject, (GLenum type, GLuint object, GLsizei length, const GLchar *label), void() ) \
	_buildFunc( void, GetObjectLabel, (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label), void() ) \
	

#define GLES_DEBUG_MARKER( _buildFunc ) \
	_buildFunc( void, InsertEventMarker, (GLsizei length, const GLchar *marker), void() ) \
	_buildFunc( void, PushGroupMarker, (GLsizei length, const GLchar *marker), void() ) \
	_buildFunc( void, PopGroupMarker, (void), void() ) \


#define GLES_DISCARD_FRAMEBUFFER( _buildFunc ) \
	_buildFunc( void, DiscardFramebuffer, (GLenum target, GLsizei numAttachments, const GLenum *attachments), void() ) \


#define GLES_MULTISAMPLED_RENDER_TO_TEXTURE( _buildFunc ) \
	_buildFunc( void, RenderbufferStorageMultisample, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height), void() ) \
	_buildFunc( void, FramebufferTexture2DMultisample, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples), void() ) \


#define GLES_MULTI_DRAW_ARRAYS( _buildFunc ) \
	_buildFunc( void, MultiDrawArrays, (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount), void() ) \
	_buildFunc( void, MultiDrawElements, (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount), void() ) \


#define GLES_OCCLUSION_QUERY_BOOLEAN( _buildFunc ) \
	_buildFunc( void, GenQueries, (GLsizei n, GLuint *ids), void() ) \
	_buildFunc( void, DeleteQueries, (GLsizei n, const GLuint *ids), void() ) \
	_buildFunc( GLboolean, IsQuery, (GLuint id), GL_FALSE ) \
	_buildFunc( void, BeginQuery, (GLenum target, GLuint id), void() ) \
	_buildFunc( void, EndQuery, (GLenum target), void() ) \
	_buildFunc( void, GetQueryiv, (GLenum target, GLenum pname, GLint *params), void() ) \
	_buildFunc( void, GetQueryObjectuiv, (GLuint id, GLenum pname, GLuint *params), void() ) \


#define GLES_ROBUSTNESS( _buildFunc ) \
	_buildFunc( GLenum, GetGraphicsResetStatus, (void), 0 ) \
	_buildFunc( void, ReadnPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data), void() ) \
	_buildFunc( void, GetnUniformfv, (GLuint program, GLint location, GLsizei bufSize, float *params), void() ) \
	_buildFunc( void, GetnUniformiv, (GLuint program, GLint location, GLsizei bufSize, GLint *params), void() ) \


#define GLES_SEPARATE_SHADER_OBJECTS( _buildFunc ) \
	_buildFunc( void, UseProgramStages, (GLuint pipeline, GLbitfield stages, GLuint program), void() ) \
	_buildFunc( void, ActiveShaderProgram, (GLuint pipeline, GLuint program), void() ) \
	_buildFunc( GLuint, CreateShaderProgramv, (GLenum type, GLsizei count, const GLchar **strings), 0 ) \
	_buildFunc( void, BindProgramPipeline, (GLuint pipeline), void() ) \
	_buildFunc( void, DeleteProgramPipelines, (GLsizei n, const GLuint *pipelines), void() ) \
	_buildFunc( void, GenProgramPipelines, (GLsizei n, GLuint *pipelines), void() ) \
	_buildFunc( GLboolean, IsProgramPipeline, (GLuint pipeline), GL_FALSE ) \
	_buildFunc( void, ProgramParameteri, (GLuint program, GLenum pname, GLint value), void() ) \
	_buildFunc( void, GetProgramPipelineiv, (GLuint pipeline, GLenum pname, GLint *params), void() ) \
	_buildFunc( void, ProgramUniform1i, (GLuint program, GLint location, GLint x), void() ) \
	_buildFunc( void, ProgramUniform2i, (GLuint program, GLint location, GLint x, GLint y), void() ) \
	_buildFunc( void, ProgramUniform3i, (GLuint program, GLint location, GLint x, GLint y, GLint z), void() ) \
	_buildFunc( void, ProgramUniform4i, (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w), void() ) \
	_buildFunc( void, ProgramUniform1f, (GLuint program, GLint location, GLfloat x), void() ) \
	_buildFunc( void, ProgramUniform2f, (GLuint program, GLint location, GLfloat x, GLfloat y), void() ) \
	_buildFunc( void, ProgramUniform3f, (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z), void() ) \
	_buildFunc( void, ProgramUniform4f, (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w), void() ) \
	_buildFunc( void, ProgramUniform1iv, (GLuint program, GLint location, GLsizei count, const GLint *value), void() ) \
	_buildFunc( void, ProgramUniform2iv, (GLuint program, GLint location, GLsizei count, const GLint *value), void() ) \
	_buildFunc( void, ProgramUniform3iv, (GLuint program, GLint location, GLsizei count, const GLint *value), void() ) \
	_buildFunc( void, ProgramUniform4iv, (GLuint program, GLint location, GLsizei count, const GLint *value), void() ) \
	_buildFunc( void, ProgramUniform1fv, (GLuint program, GLint location, GLsizei count, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniform2fv, (GLuint program, GLint location, GLsizei count, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniform3fv, (GLuint program, GLint location, GLsizei count, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniform4fv, (GLuint program, GLint location, GLsizei count, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniformMatrix2fv, (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniformMatrix3fv, (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value), void() ) \
	_buildFunc( void, ProgramUniformMatrix4fv, (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value), void() ) \
	_buildFunc( void, ValidateProgramPipeline, (GLuint pipeline), void() ) \
	_buildFunc( void, GetProgramPipelineInfoLog, (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog), void() ) \


#define GLES_TEXTURE_STORAGE( _buildFunc ) \
	_buildFunc( void, TexStorage1D, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width), void() ) \
	_buildFunc( void, TexStorage2D, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height), void() ) \
	_buildFunc( void, TexStorage3D, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth), void() ) \
	_buildFunc( void, TextureStorage1D, (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width), void() ) \
	_buildFunc( void, TextureStorage2D, (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height), void() ) \
	_buildFunc( void, TextureStorage3D, (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth), void() ) \



namespace gles
{

/* GL_OES_compressed_ETC1_RGB8_texture */
namespace OES_compressed_ETC1_RGB8_texture {
	enum {
		GL_ETC1_RGB8                                      = 0x8D64
	};
	GLES_API bool IsSupported();
}


/* GL_OES_compressed_paletted_texture */
namespace OES_compressed_paletted_texture {
	enum {
		GL_PALETTE4_RGB8                                  = 0x8B90,
		GL_PALETTE4_RGBA8                                 = 0x8B91,
		GL_PALETTE4_R5_G6_B5                              = 0x8B92,
		GL_PALETTE4_RGBA4                                 = 0x8B93,
		GL_PALETTE4_RGB5_A1                               = 0x8B94,
		GL_PALETTE8_RGB8                                  = 0x8B95,
		GL_PALETTE8_RGBA8                                 = 0x8B96,
		GL_PALETTE8_R5_G6_B5                              = 0x8B97,
		GL_PALETTE8_RGBA4                                 = 0x8B98,
		GL_PALETTE8_RGB5_A1                               = 0x8B99,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_depth24 */
namespace OES_depth24 {
	enum {
		GL_DEPTH_COMPONENT24                              = 0x81A6
	};
	GLES_API bool IsSupported();
}


/* GL_OES_depth32 */
namespace OES_depth32 {
	enum {
		GL_DEPTH_COMPONENT32                              = 0x81A7,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_element_index_uint */
namespace OES_element_index_uint {
	enum {
		GL_UNSIGNED_INT                                    = 0x1405,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_get_program_binary */
namespace OES_get_program_binary {
	enum {
		GL_PROGRAM_BINARY_LENGTH                          = 0x8741,
		GL_NUM_PROGRAM_BINARY_FORMATS                     = 0x87FE,
		GL_PROGRAM_BINARY_FORMATS                         = 0x87FF,
	};
	GLES_GET_PROGRAM_BINARY( GLES_BUILDTYPEDEF )
	GLES_GET_PROGRAM_BINARY( GLES_BUILDFUNC )

	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_OES_mapbuffer */
namespace OES_mapbuffer {
	enum {
		GL_WRITE_ONLY                                     = 0x88B9,
		GL_BUFFER_ACCESS                                  = 0x88BB,
		GL_BUFFER_MAPPED                                  = 0x88BC,
		GL_BUFFER_MAP_POINTER                             = 0x88BD,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_packed_depth_stencil */
namespace OES_packed_depth_stencil {
	enum {
		GL_DEPTH_STENCIL                                  = 0x84F9,
		GL_UNSIGNED_INT_24_8                              = 0x84FA,
		GL_DEPTH24_STENCIL8                               = 0x88F0,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_rgb8_rgba8 */
namespace OES_rgb8_rgba8 {
	enum {
		GL_RGB8                                           = 0x8051,
		GL_RGBA8                                          = 0x8058,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_standard_derivatives */
namespace OES_standard_derivatives {
	enum {
		GL_FRAGMENT_SHADER_DERIVATIVE_HINT                = 0x8B8B,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_stencil1 */
namespace OES_stencil1 {
	enum {
		GL_STENCIL_INDEX1                                 = 0x8D46,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_stencil4 */
namespace OES_stencil4 {
	enum {
		GL_STENCIL_INDEX4                                 = 0x8D47,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_texture_3D */
namespace OES_texture_3D {
	enum {
		GL_TEXTURE_WRAP_R                                 = 0x8072,
		GL_TEXTURE_3D                                     = 0x806F,
		GL_TEXTURE_BINDING_3D                             = 0x806A,
		GL_MAX_3D_TEXTURE_SIZE                            = 0x8073,
		GL_SAMPLER_3D                                     = 0x8B5F,
		GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET      = 0x8CD4,
	};
	GLES_TEXTURE_3D( GLES_BUILDTYPEDEF )
	GLES_TEXTURE_3D( GLES_BUILDFUNC )

	GLES_BUILDCONST( GLint, MAX_3D_TEXTURE_SIZE )

	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}

/* OES_texture_float */
namespace OES_texture_float {
	GLES_API bool IsSupported();
}

/* GL_OES_texture_half_float */
namespace OES_texture_half_float {
	enum {
		GL_HALF_FLOAT                                     = 0x8D61,
	};
	GLES_API bool IsSupported();
}

/* GL_OES_vertex_half_float */
namespace OES_vertex_half_float {
	enum {
		GL_HALF_FLOAT                                     = 0x8D61,
	};
	GLES_API bool IsSupported();
}


/* GL_OES_vertex_array_object */
namespace OES_vertex_array_object {
	enum {
		GL_VERTEX_ARRAY_BINDING                           = 0x85B5,
	};
	GLES_VERTEX_ARRAY_OBJECT( GLES_BUILDTYPEDEF )
	GLES_VERTEX_ARRAY_OBJECT( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_OES_vertex_type_10_10_10_2 */
namespace OES_vertex_type_10_10_10_2 {
	enum {
		GL_UNSIGNED_INT_10_10_10_2                        = 0x8DF6,
		GL_INT_10_10_10_2                                 = 0x8DF7,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_blend_minmax */
namespace EXT_blend_minmax {
	enum {
		GL_MIN                                            = 0x8007,
		GL_MAX                                            = 0x8008,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_color_buffer_half_float */
namespace EXT_color_buffer_half_float {
	enum {
		GL_RGBA16F                                        = 0x881A,
		GL_RGB16F                                         = 0x881B,
		GL_RG16F                                          = 0x822F,
		GL_R16F                                           = 0x822D,
		GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE          = 0x8211,
		GL_UNSIGNED_NORMALIZED                            = 0x8C17,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_debug_label */
namespace EXT_debug_label {
	enum {
		GL_PROGRAM_PIPELINE_OBJECT                        = 0x8A4F,
		GL_PROGRAM_OBJECT                                 = 0x8B40,
		GL_SHADER_OBJECT                                  = 0x8B48,
		GL_BUFFER_OBJECT                                  = 0x9151,
		GL_QUERY_OBJECT                                   = 0x9153,
		GL_VERTEX_ARRAY_OBJECT                            = 0x9154,
	};
	GLES_DEBUG_LABEL( GLES_BUILDTYPEDEF )
	GLES_DEBUG_LABEL( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_debug_marker */
namespace EXT_debug_marker {
	
	GLES_DEBUG_MARKER( GLES_BUILDTYPEDEF )
	GLES_DEBUG_MARKER( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_discard_framebuffer */
namespace EXT_discard_framebuffer {
	enum {
		GL_COLOR                                          = 0x1800,
		GL_DEPTH                                          = 0x1801,
		GL_STENCIL                                        = 0x1802,
	};
	GLES_DISCARD_FRAMEBUFFER( GLES_BUILDTYPEDEF )
	GLES_DISCARD_FRAMEBUFFER( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_multisampled_render_to_texture */
namespace EXT_multisampled_render_to_texture {
	enum {
		GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES         = 0x8D6C,
		GL_RENDERBUFFER_SAMPLES                           = 0x9133,
		GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE             = 0x9134,
		GL_MAX_SAMPLES                                    = 0x9135,
	};
	GLES_MULTISAMPLED_RENDER_TO_TEXTURE( GLES_BUILDTYPEDEF )
	GLES_MULTISAMPLED_RENDER_TO_TEXTURE( GLES_BUILDFUNC )
	
	GLES_BUILDCONST( GLint, MAX_SAMPLES )

	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_multi_draw_arrays */
namespace EXT_multi_draw_arrays {
	
	GLES_MULTI_DRAW_ARRAYS( GLES_BUILDTYPEDEF )
	GLES_MULTI_DRAW_ARRAYS( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_occlusion_query_boolean */
namespace EXT_occlusion_query_boolean {
	enum {
		GL_ANY_SAMPLES_PASSED                             = 0x8C2F,
		GL_ANY_SAMPLES_PASSED_CONSERVATIVE                = 0x8D6A,
		GL_CURRENT_QUERY                                  = 0x8865,
		GL_QUERY_RESULT                                   = 0x8866,
		GL_QUERY_RESULT_AVAILABLE                         = 0x8867,
	};
	GLES_OCCLUSION_QUERY_BOOLEAN( GLES_BUILDTYPEDEF )
	GLES_OCCLUSION_QUERY_BOOLEAN( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_read_format_bgra */
namespace EXT_read_format_bgra {
	enum {
		GL_BGRA                                           = 0x80E1,
		GL_UNSIGNED_SHORT_4_4_4_4_REV                     = 0x8365,
		GL_UNSIGNED_SHORT_1_5_5_5_REV                     = 0x8366,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_robustness */
namespace EXT_robustness {
	enum {
		/* reuse GL_NO_ERROR */
		GL_GUILTY_CONTEXT_RESET                           = 0x8253,
		GL_INNOCENT_CONTEXT_RESET                         = 0x8254,
		GL_UNKNOWN_CONTEXT_RESET                          = 0x8255,
		GL_CONTEXT_ROBUST_ACCESS                          = 0x90F3,
		GL_RESET_NOTIFICATION_STRATEGY                    = 0x8256,
		GL_LOSE_CONTEXT_ON_RESET                          = 0x8252,
		GL_NO_RESET_NOTIFICATION                          = 0x8261,
	};
	GLES_ROBUSTNESS( GLES_BUILDTYPEDEF )
	GLES_ROBUSTNESS( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_separate_shader_objects */
namespace EXT_separate_shader_objects {
	enum {
		GL_VERTEX_SHADER_BIT                              = 0x00000001,
		GL_FRAGMENT_SHADER_BIT                            = 0x00000002,
		GL_ALL_SHADER_BITS                                = 0xFFFFFFFF,
		GL_PROGRAM_SEPARABLE                              = 0x8258,
		GL_ACTIVE_PROGRAM                                 = 0x8259,
		GL_PROGRAM_PIPELINE_BINDING                       = 0x825A,
	};
	GLES_SEPARATE_SHADER_OBJECTS( GLES_BUILDTYPEDEF )
	GLES_SEPARATE_SHADER_OBJECTS( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_shadow_samplers */
namespace EXT_shadow_samplers {
	enum {
		GL_TEXTURE_COMPARE_MODE                           = 0x884C,
		GL_TEXTURE_COMPARE_FUNC                           = 0x884D,
		GL_COMPARE_REF_TO_TEXTURE                         = 0x884E,
		GL_SAMPLER_2D_SHADOW                              = 0x8B62,
	};
	GLES_API bool IsSupported();
	/*
	in GLSL:
		#extension GL_EXT_shadow_samplers : require
		float shadow2DEXT(sampler2DShadow sampler, vec3 coord);
		float shadow2DProjEXT(sampler2DShadow sampler, vec4 coord);
	*/
}


/* GL_EXT_sRGB */
namespace EXT_sRGB {
	enum {
		GL_SRGB                                           = 0x8C40,
		GL_SRGB_ALPHA                                     = 0x8C42,
		GL_SRGB8_ALPHA8                                   = 0x8C43,
		GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING          = 0x8210,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_texture_compression_dxt1 */
namespace EXT_texture_compression_dxt1 {
	enum {
		GL_COMPRESSED_RGB_S3TC_DXT1                       = 0x83F0,
		GL_COMPRESSED_RGBA_S3TC_DXT1                      = 0x83F1,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_texture_filter_anisotropic */
namespace EXT_texture_filter_anisotropic {
	enum {
		GL_TEXTURE_MAX_ANISOTROPY                         = 0x84FE,
		GL_MAX_TEXTURE_MAX_ANISOTROPY                     = 0x84FF,
	};
	GLES_BUILDCONST( GLfloat, MAX_TEXTURE_MAX_ANISOTROPY )

	GLES_API bool IsSupported();
}


/* GL_EXT_texture_format_BGRA8888 */
namespace EXT_texture_format_BGRA8888 {
	enum {
		GL_BGRA                                           = 0x80E1,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_texture_rg */
namespace EXT_texture_rg {
	enum {
		GL_RED                                            = 0x1903,
		GL_RG                                             = 0x8227,
		GL_R8                                             = 0x8229,
		GL_RG8                                            = 0x822B,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_texture_storage */
namespace EXT_texture_storage {
	enum {
		GL_TEXTURE_IMMUTABLE_FORMAT                       = 0x912F,
		GL_ALPHA8                                         = 0x803C, 
		GL_LUMINANCE8                                     = 0x8040,
		GL_LUMINANCE8_ALPHA8                              = 0x8045,
		GL_RGBA32F                                        = 0x8814, 
		GL_RGB32F                                         = 0x8815,
		GL_ALPHA32F                                       = 0x8816,
		GL_LUMINANCE32F                                   = 0x8818,
		GL_LUMINANCE_ALPHA32F                             = 0x8819,
		GL_RGBA16F										  = EXT_color_buffer_half_float::GL_RGBA16F,
		GL_RGB16F										  = EXT_color_buffer_half_float::GL_RGB16F,
		GL_ALPHA16F                                       = 0x881C,
		GL_LUMINANCE16F                                   = 0x881E,
		GL_LUMINANCE_ALPHA16F                             = 0x881F,
		GL_RGB10_A2                                       = 0x8059, 
		GL_RGB10                                          = 0x8052,
		GL_BGRA8                                          = 0x93A1,
		GL_R8                                             = 0x8229,
		GL_RG8                                            = 0x822B,
		GL_R32F                                           = 0x822E, 
		GL_RG32F                                          = 0x8230,
		GL_R16F                                           = 0x822D,
		GL_RG16F                                          = 0x822F,
	};
	GLES_TEXTURE_STORAGE( GLES_BUILDTYPEDEF )
	GLES_TEXTURE_STORAGE( GLES_BUILDFUNC )
	
	GLES_API bool IsSupported();
	GLES_API bool LoadExtension();
	GLES_API void UnloadExtension();
}


/* GL_EXT_texture_type_2_10_10_10_REV */
namespace EXT_texture_type_2_10_10_10_REV {
	enum {
		GL_UNSIGNED_INT_2_10_10_10_REV                    = 0x8368,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_unpack_subimage */
namespace EXT_unpack_subimage {
	enum {
		GL_UNPACK_ROW_LENGTH                               = 0x0CF2,
		GL_UNPACK_SKIP_ROWS                                = 0x0CF3,
		GL_UNPACK_SKIP_PIXELS                              = 0x0CF4,
	};
	GLES_API bool IsSupported();
}


/* GL_EXT_frag_depth */
namespace EXT_frag_depth {
	GLES_API bool IsSupported();
	/*
	in GLSL:
		#extension GL_EXT_frag_depth : enable
		highp float gl_FragDepthEXT; // if OES_fragment_precision_high supported
		mediump float gl_FragDepthEXT;
	*/
}

/* GL_OES_fragment_precision_high */
namespace OES_fragment_precision_high {
	GLES_API bool IsSupported();
	/*
	in GLSL:
		precision highp float;
	*/
}

//-------------------------------------------------------------------

}	// gles
